/*
* @Author: ZHELIHAO\fangshuqin
* @Date:   2018-05-21 16:29:46
* @Last Modified by:   ZHELIHAO\fangshuqin
* @Last Modified time: 2018-05-26 14:48:36
*/

{
    let EVENT_CLICK = Laya.Event.CLICK;
    
    class Myinfo extends ui.Hall.MyInfoUI {
        constructor () {
            super();
            
            this.init();
        }


        init () {
            this.initEvent();
            this.initConfig();
            this.registerActions();
            
        }

               // 初始化配置
        initConfig() {
            this.config = {
                MAX_WIDTH: 240,
                MIN_WIDTH: 17

            }
        }


        initEvent(){
            // 个人信息详情
            this.dom_icon.on(EVENT_CLICK, this, ()=>{
                Public.BetAndSet.I.exit();
                
                Laya.loader.load(ASSETS.INFO, Laya.Handler.create(null, function () {
                    let info = new Scene.Info();
                    Sail.director.runScene(info);
                }));
            })
        }

        registerActions () {
            this.ACTIONS = {
                 [GAME_CMDS.USE_INFO]  : this.getUserInfo,
            };
            Sail.io.register(this.ACTIONS, this);
        }

        getUserInfo(data) {
            console.log("getUserInfo", data);
            this.dom_icon.skin = 'res/role_icon/icon_1.png';
            this.dom_frame.skin = 'res/role_icon/frame_1.png';
            if (data.icon) {
                this.dom_icon.skin = `res/role_icon/icon_${data.icon}.png`;
            }
            if (data.frame) {
                this.dom_frame.skin = `res/role_icon/frame_${data.frame}.png`;
            }
            
            this.dom_viplvl.text = data.vip_lvl;
            this.dom_explevel.text = data.exp_lvl;
            this.dom_nickname.text = data.nick_name;

            // 段位
            let userGrade =  Sail.store.getUserGrade(Number(data.grade));

            let grade_mole = data.cup_num - userGrade.cup_num;  //分子
                grade_mole >0 ? grade_mole :0;
            let grade_deno = userGrade.next_cup_num;          //分母
            let grade_progress = grade_mole / grade_deno;

            let grade_per = Math.floor( grade_progress * 100 );
            let grade_w = grade_per / 100 * this.config.MAX_WIDTH;

            grade_w = grade_w < this.config.MIN_WIDTH ? this.config.MIN_WIDTH : grade_w; 

            this.dom_progress.scrollRect = {x : 0, y : 0, width : grade_w, height : 42};
            this.dom_progress.visible = true;

            this.dom_cupnum.text = userGrade.cup_num + '/' +  userGrade.next_cup_num ;
            this.grade.index = Number(userGrade.icon);

        }

        exit () {
            Sail.io.unregister(this.ACTIONS);
        }
    }

    Sail.class(Myinfo, "Com.Hall.Myinfo");
}